package com.xiebishe.mylibrary.common.pageStatus.centerHandler;

import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;

public class ConstraintLayoutHandler extends CenterStatusHandler<ConstraintLayout> {

    public ConstraintLayoutHandler(@NonNull ConstraintLayout layout) {
        super(layout);
    }

    @Override
    protected void addToCenter(@NonNull View view, @NonNull ConstraintLayout layout) {
        ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
        if (layoutParams != null) {
            layout.addView(view);
        } else {
            ConstraintLayout.LayoutParams layoutParams1 = new ConstraintLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            layoutParams1.topToTop = ConstraintLayout.LayoutParams.PARENT_ID;
            layoutParams1.startToStart = ConstraintLayout.LayoutParams.PARENT_ID;
            layoutParams1.endToEnd = ConstraintLayout.LayoutParams.PARENT_ID;
            layoutParams1.bottomToBottom = ConstraintLayout.LayoutParams.PARENT_ID;
            layout.addView(view, layoutParams1);
        }
    }

    @Override
    protected void removeView(@NonNull View view, @NonNull ConstraintLayout layout) {
        layout.removeView(view);
    }

    @Override
    protected boolean onHideContent(@NonNull ConstraintLayout layout) {
        setAllInvisible(layout);
        return true;
    }

    @Override
    protected boolean onShowContent(@NonNull ConstraintLayout layout) {
        restoreLastVisibility(layout);
        return true;
    }
}
